package com.sise.wangzhan;

import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Classname MyController
 * @Description TODO
 * @Date 2020/3/25 15:27
 * @Created by wangzhan
 */
@RestController
public class MyController {

    @RequestMapping(value = "/person/{person_id}", method = RequestMethod.GET)
    public String findName(@PathVariable("person_id") Integer person_id, HttpServletRequest request){
        Person person = new Person(person_id, "wangzhan", 22);
        person.setMessage(request.getRequestURL().toString());

        Map<String,String> map = new HashMap<>();
        map.put("person_id", person.getPerson_id().toString());
        map.put("p_name",person.getP_name());
        map.put("p_age", Integer.toString(person.getP_age()));
        map.put("message:", person.getMessage());

        String s = JSON.toJSONString(map);

        return s;
    }

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String hello(){
        return "hello";
    }
}
